package everyday;

/**
 * @Author: Siantar
 * @Date: 2023-06-05-11:50
 * @Description: 1.0
 */
public class T2460 {
    public int[] applyOperations(int[] nums) {
        int n = nums.length;
        int[] res = new int[n];
        int pre = 0;
        for (int i = 0; i < n - 1; i++) {
            if (nums[i] == nums[i + 1]) {
                nums[i] *= 2;
                nums[i + 1] = 0;
            }
            if (nums[i] != 0) {
                res[pre++] = nums[i];
            }
        }
        if (nums[n - 1] != 0) res[pre] = nums[n - 1];
        return res;
    }
}
